package com.tensai.utils.xml;

import cn.hutool.core.io.FileUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.StringWriter;
import java.io.Writer;

/**
 * @author Tensai
 */
@Slf4j
@SuppressWarnings("all")
public class XmlUtilTest {




	public String reFormat(String xml) {
		cn.hutool.core.util.XmlUtil.parseXml(xml);
		return null;

	}

	@Test
	public void test() throws JAXBException {
		A a = new A(new B(new C(new D(new E(new F(new G(new H(new I(new J(new K(new L(new M(new N("qweqwe"))))))))))))));

		JAXBContext jbt = JAXBContext.newInstance(A.class);
		Marshaller ms = jbt.createMarshaller();
		ms.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		Writer writer = new StringWriter();
		ms.marshal(a, writer);
		String xml = FileUtil.readUtf8String(writer.toString());
		String xmlFormat = cn.hutool.core.util.XmlUtil.format(xml);
		log.info(xmlFormat);


	}
}
@Data @AllArgsConstructor @NoArgsConstructor
@XmlRootElement class A{ private B b;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class B{ private C c;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class C{ private D d;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class D{ private E e;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class E{ private F f;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class F{ private G g;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class G{ private H h;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class H{ private I i;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class I{ private J j;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class J{ private K k;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class K{ private L l;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class L{ private M m;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class M{ private N n;}
@Data @AllArgsConstructor @NoArgsConstructor @XmlRootElement class N{ private String o;}